package com.tanhua.server.controller;

import com.tanhua.server.service.CommentService;
import com.tanhua.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 返回评论列表
     *
     * @param page
     * @param pagesize
     * @param movementId
     * @return
     */
    @GetMapping
    public ResponseEntity getComments(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,
                                      String movementId) {
        PageResult pageResult = commentService.getComments(movementId, page, pagesize);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 发布评论方法
     *
     * @param map
     * @return
     */
    @PostMapping
    public ResponseEntity publish(@RequestBody Map map) {
        String movementId = (String) map.get("movementId");
        String comment = (String) map.get("comment");

        commentService.publish(movementId, comment);

        return ResponseEntity.ok(null);
    }


}
